package br.ucb.sigplan.action.impl;

import java.io.IOException;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import br.ucb.sigplan.action.Action;
import br.ucb.sigplan.beans.Curso;
import br.ucb.sigplan.crud.CursoCrud;

public class AbrirListarCursoAction implements Action{

	@Override
	public String execute(HttpServletRequest req, HttpServletResponse resp)
			throws ServletException, IOException {
		List<Curso> cursos = CursoCrud.findAll();
		if (cursos.isEmpty()) {
			req.setAttribute("msg", "cursosVazio");
			return "/jsp/index.jsp";
		}
		req.setAttribute("cursos", cursos);
		return "/jsp/diretor/curso/dirListaCursos.jsp";
	}

}
